


import { createSlice } from '@reduxjs/toolkit'


const userSlice = createSlice({
    name: 'user',
    initialState: {
        users: localStorage.users ? JSON.parse(localStorage.users) : [],
        currentUser: null,
        num:10
    },
    reducers: {
        addUser(state, action) {
                state.users.push(action.payload);
                localStorage.users = JSON.stringify(state.users)
        },
        setCurrentUser(state, action) {
            state.currentUser = action.payload;
        },
         removeUser(state, action) {
      state.users = state.users.filter(user => user.id !== action.payload);
      localStorage.setItem('users', JSON.stringify(state.users));
    },

        editUser(state,action){

        },
        // clearCurrentUser(state) {
        //     state.currentUser = null;
        // }

        setNum(state,action){
            state.num=action.payload
        }
    }
})



export default userSlice
export const { addUser ,setCurrentUser,removeUser,editUser,setNum} = userSlice.actions